package com.sc.nft.entity.dto;

import cn.hutool.core.util.StrUtil;
import com.sc.nft.entity.MallProduct;
import com.sc.nft.enums.ApprovalStatusEnum;
import com.sc.nft.enums.ProductTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.Transient;

import java.util.List;

/**
 * 商品DTO
 *
 * @author liGen
 * @version 1.0
 * @date 2023/11/13 10:53 上午
 */
@Data
public class MallProductDTO {


    @ApiModelProperty(value = "商品Id")
    private Long id;

    @ApiModelProperty(value = "商品类型")
    private ProductTypeEnum type;

    @ApiModelProperty(value = "分类Id")
    private Long categoryId;

    @ApiModelProperty(value = "封面图")
    private List<String> coverImages;


    @ApiModelProperty(value = "缩略图")
    private String thumbnail;

    @ApiModelProperty(value = "商品编码")
    @Transient
    private String productCode;

    @ApiModelProperty(value = "商品标题")
    private String productName;

    @ApiModelProperty(value = "审批状态")
    private ApprovalStatusEnum approvalStatus;

    @ApiModelProperty(value = "商品详情")
    private List<String> productDetail;

    @ApiModelProperty(value = "审核备注")
    private String remark;

    @ApiModelProperty(value = "上架中的活动数量")
    private Long onShelfActivityCount;


    public static MallProductDTO build(MallProduct mallProduct){
        MallProductDTO mallProductDTO = new MallProductDTO();
        mallProductDTO.setId(mallProduct.getId());
        mallProductDTO.setType(mallProduct.getType());
        mallProductDTO.setCategoryId(mallProduct.getCategoryId());
        mallProductDTO.setCoverImages(StrUtil.split(mallProduct.getCoverImage(), ","));
        mallProductDTO.setThumbnail(mallProduct.getThumbnail());
        mallProductDTO.setProductCode(mallProduct.getProductCode());
        mallProductDTO.setProductName(mallProduct.getProductName());
        mallProductDTO.setProductDetail(StrUtil.split(mallProduct.getProductDetail(), ","));
        mallProductDTO.setApprovalStatus(mallProduct.getApprovalStatus());
        mallProductDTO.setRemark(mallProduct.getRemark());
        return mallProductDTO;
    }
}
